<template>
	<view style="padding-bottom: 20rpx;">

		<uni-forms label-position="top" label-width="105px" style="padding-bottom: 100rpx;">

			<uni-notice-bar single text="-1代表 不参与测评。不会生成报告"></uni-notice-bar>


			<uni-section title="客户信息" type="circle" padding>
				<view class="">

					<view style="font-size: 34rpx;font-weight: bold;margin-bottom: 10rpx;">
						{{ editData.student.name }}
					</view>

					{{ editData.axParentsDO.phone }}&nbsp;&nbsp;|&nbsp;&nbsp;
					{{ dateToAge(editData.student.dateOfBirth)}}&nbsp;&nbsp;|&nbsp;&nbsp;{{editData.student.sex == 0?'女':'男'}}


					<uni-row>
						<uni-col :span="12">
							<uni-forms-item label="身高(cm)">
								<uni-easyinput :clearable="false" v-model="editData.student.height" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>


						<uni-col :span="12">
							<uni-forms-item label="体重(kg)" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.student.weight"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

					</uni-row>
				</view>
			</uni-section>

			<uni-section title="感觉统合发展评量表" type="circle">
				<view class="margin-sm">

					<uni-row :gutter="10">
						<uni-col :span="12">
							<uni-forms-item label="前庭觉" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.gtQtphg" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="本体感" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.gtBtj" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="触 觉" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.gtCjfyj" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>
				</view>
			</uni-section>

			<uni-section title="运动能力" type="circle">
				<view class="margin-sm">
					<uni-row :gutter="10">
						<view style="background-color: #f5f5f5;padding: 10rpx;">单脚站</view>


						<uni-col :span="12">
							<uni-forms-item label="左脚" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.djzZ" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="右脚" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.djzY" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

					</uni-row>

					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">闭眼原地踏步</view>
						<br>
						<uni-col :span="12">
							<uni-forms-item label="1分钟是否完成 " prop="grade">
								<uni-data-checkbox v-model="editData.byydtb1"
									:localdata="[{text:'是',value:'1'},{text:'否',value:'0'}]" size="medium">

								</uni-data-checkbox>
							</uni-forms-item>
						</uni-col>


						<uni-col :span="12">
							<uni-forms-item label="动作是否标准 " prop="grade">
								<uni-data-checkbox v-model="editData.dzsfbz"
									:localdata="[{text:'是',value:'1'},{text:'否',value:'0'}]" size="medium">

								</uni-data-checkbox>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">

							<uni-forms-item label="身体是否偏移 " prop="grade">
								<uni-data-checkbox v-model="editData.stsfpy"
									:localdata="[{text:'是',value:'1'},{text:'否',value:'0'}]" size="medium">

								</uni-data-checkbox>
							</uni-forms-item>
						</uni-col>
						<uni-col v-if="editData.stsfpy ==1" :span="12">
							<uni-forms-item label="旋转 " prop="grade">
								<uni-data-checkbox v-model="editData.byydtbxz"
									:localdata="[{text:'是',value:'1'},{text:'否',value:'0'}]" size="medium">

								</uni-data-checkbox>
							</uni-forms-item>
						</uni-col>

						<uni-col :span="12">
							<uni-forms-item label="立定跳远(cm)" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.ldty" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

					</uni-row>
				</view>
			</uni-section>

			<uni-section title="听知觉" type="circle">
				<view class="margin-sm">
					<uni-row :gutter="10">
						<view style="background-color: #f5f5f5;padding: 10rpx;">听广度</view>

						<uni-col :span="12">
							<uni-forms-item label="顺数" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.tgdss" :max="10" :min="-1"
									label="描述文字" style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">

							<uni-forms-item label="拼音仿说" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.tgdfspy" :max="10" :min="-1"
									label="描述文字" style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">

							<uni-forms-item label="句子仿说" prop="grade">
								<uni-data-select v-model="editData.tgdjzfs" placeholder="请选择"
									:localdata="options"></uni-data-select>
							</uni-forms-item>
						</uni-col>
					</uni-row>
					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">听分辨</view>

						<uni-col :span="12">

							<uni-forms-item label="累计听音 " prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.tfbljty" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="错误 " prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.tfbcw" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>
					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">听记忆</view>


						<uni-col :span="12">
							<uni-forms-item label="倒数 " prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.tjyds" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>
					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">句子仿说提问</view>


						<uni-col :span="12">
							<uni-forms-item label="问题数量 " prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.jzfstwwtsl" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="错误数量 " prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.jzfstwcwsl" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

					</uni-row>

				</view>
			</uni-section>

			<uni-section title="视知觉" type="circle">
				<view class="margin-sm">

					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">
							视分辨
						</view>

						<uni-col :span="12">
							<uni-forms-item label="应划掉 " prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.sfbyhd" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="划错 " prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.sfbhc" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

						<uni-col :span="12">
							<uni-forms-item label="划漏" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.sfbhl" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

					</uni-row>

					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">
							视广度
						</view>

						<uni-col :span="12">

							<uni-forms-item label="视广度完成率" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.sfbsgdwcl" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="视动统合能力" prop="grade">


								<uni-easyinput :clearable="false" v-model="editData.sfbsdthnl" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>

					<uni-row>
						<view style="background-color: #f5f5f5;padding: 10rpx;">
							视动速度
						</view>

						<uni-col :span="12">

							<uni-forms-item label="抄写个数" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.sfbsdsd" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">

							<uni-forms-item label="错误" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.sfbcw" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>
				</view>
			</uni-section>

			<uni-section title="思维能力" type="circle">
				<view class="margin-sm">

					<uni-row>
						<uni-col :span="12">
							<uni-forms-item label="思维分数" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.swswfs" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

						<uni-col :span="12">

							<uni-forms-item label="百分比" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.swbfb" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

						<uni-col :span="12">

							<uni-forms-item label="思维IQ值" prop="grade">

								<uni-easyinput :clearable="false" v-model="editData.swiq" :min="-1" label="描述文字"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>
				</view>
			</uni-section>
		</uni-forms>
		<view class="dialog-footer  fixed-bottom padding" style="display: flex;">

			<button class="login-btn cu-btn block bg-blue lg round margin-top-sm" style="width: 300rpx" @click="save"
				v-if="status==1">重新测评</button>
			<button class="login-btn cu-btn block bg-blue lg round margin-top-sm"
				style="width: 430rpx;margin-left: 20rpx;" @click="download" v-if="status==1">下
				载测评报告</button>

			<button class="login-btn cu-btn block bg-blue lg round margin-top-sm" style="width: 750rpx;" @click="save"
				v-if="status!=1">测评</button>
		</view>

	</view>
</template>

<script>
	import {
		doAddCp,
		getLishi,
		getById
	} from '@/api/marketing/evaluation/AxEvaluationRecordManagementApi'
	import config from '@/config'
	import {
		evaluationPlan
	} from "@/utils/common.js";
	import {
		formatTime,
		dateToAge,
		isJson
	} from '@/utils/validate'
	export default {
		name: 'Xq',

		data() {
			return {
				data: '',
				axParentsDO: {
					phone: '',
				},
				options: [{
						value: 1,
						text: "T1",
					},
					{
						value: 2,
						text: "T2",
					},
					{
						value: 3,
						text: "T3",
					},
					{
						value: 4,
						text: "T4",
					},
					{
						value: 5,
						text: "T5",
					},
					{
						value: 6,
						text: "T6",
					},
					{
						value: 7,
						text: "T7",
					},
					{
						value: 8,
						text: "T8",
					},
					{
						value: 9,
						text: "T9",
					},
				],
				editData: {
					id: '',
					customerModel: {
						student: {
							name: ""
						},
						parentsInfo: {}
					},
					student: {
						name: ""
					},
					axParentsDO: {}
				},
				axParentsDO: {},
				dialogFormVisible: false,
				status: 0,
				asdfasdf: {}
			}
		},
		onLoad(e) {
			if (e.id != null) {
				this.editData.erid = e.id

				this.getEvaluation()
			}
		},
		methods: {
			download(row) {
				var adfas1 = ''
				var adfas2 = ''
				var mymessage = confirm("需要同时发送至家长微信吗?");
				if (mymessage == true) {

				} else {

				}


				this.getProgress(config.baseUrl + "/" + this.asdfasdf.evaluationPlanUrl, this.asdfasdf.evaluationPlanUrl
					.split('/')[this.asdfasdf
						.evaluationPlanUrl.split('/').length - 1], adfas1)

			},
			getProgress(url, aa) {
				window.open(url, '_blank');

			},
			async getEvaluation() {
				console.log(this.editData);
				const {
					msg,
					data,
					success
				} = await getById({
					id: this.editData.erid
				})
				if (success) {
					this.asdfasdf = data
					this.showEdit(data)
				}

			},
			// 复制
			handleClipboard(event) {
				clipboard(JSON.stringify(this.editData), event);
			},
			async save() {

				if (this.editData.stsfpy == "0") {
					this.editData.byydtbxz = '0'

				}

				this.editData.lishi = null
				this.editData.lishi = JSON.stringify(this.editData).replace(/[\\]/g, '');
				let _this = this
				const {
					msg,
					success
				} = await doAddCp(this.editData)
				if (success) {
					uni.showModal({
						title: "测评成功",
						content: "下载按钮将出现在右下角",
						success() {
							_this.getEvaluation()
						}
					})


				}


			},
			dateToAge(date) {
				return dateToAge(date)
			},
			async showEdit(row) {
				this.editData = JSON.parse(JSON.stringify(evaluationPlan))
				this.status = row.status
				this.editData.evaluationGrade = row.evaluationGrade
				this.editData.gradetype = 'xlq'
				this.editData.erid = row.id

				this.editData.student.id = row.student.id
				this.editData.student.dateOfBirth = row.student.dateOfBirth
				this.editData.student.height = row.student.height
				this.editData.student.weight = row.student.weight
				this.editData.student.sex = row.student.sex
				this.editData.student.name = row.student.name
				this.axParentsDO = row.parentsInfo // this.editData = this.common.evaluationPlan
				this.editData.axParentsDO.phone = row.parentsInfo.phone
				this.editData.student.age2 = dateToAge(
					this.editData.student.dateOfBirth
				)
				// this.editData = Object.assign({}, JSON.parse(JSON.stringify(evaluationPlan)), this.editData);
				// this.editData.gradetype = 'xlq'
				// this.editData.erid = this.editData.id
				const {
					msg,
					success,
					data
				} = await getLishi({
					erid: row.id,
					evaluationGrade: this.editData.evaluationGrade
				})

				if (data.lishi != null) {
					if (!isJson(data.lishi)) {
						uni.showModal({
							title: "历史数据异常",
							content: "检测到有历史数据，但是是异常的数据。但不影响新的测评。如有需要请联系青与澜"
						})

						return
					}
					this.editData = JSON.parse(data.lishi)
					uni.showToast({
						icon: "none",
						title: "历史数据加载成功"
					})
				}
			},
		},
	}
</script>

<style scoped>
	.el-dialog__header {
		text-align: center;
	}

	.uni-forms-item--small.uni-forms-item {
		margin-bottom: 18px;
		margin-left: 40px;
	}

	.uni-form--label-top .uni-forms-item__label {
		float: none;
		display: inline-block;
		text-align: left;
	}

	.el-dialog__title {
		color: #ff0000;
		font-weight: 1000;
	}

	.view--small {
		height: 24px;
		padding: 0 8px;
		line-height: 22px;
		/*width: 250rpx;*/
	}
</style>